package com.bw.publish.ui

import android.app.ProgressDialog
import android.os.Bundle
import android.os.Environment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bw.mvicore.ui.BaseFragment
import com.bw.publish.common.ConstantValue
import com.bw.publish.databinding.FragmentPublishBinding
import com.bw.publish.utils.AliOssUtils
import com.bw.publish.utils.Callback
import java.io.File


/**
 * @author:created by hahajing
 * 时间：2024/4/24 0024
 * 企鹅号:444511958
 * 描述:
 */
class PublishFragment:BaseFragment() {
    private lateinit var binding: FragmentPublishBinding
    override fun initEvent() {
        binding.tvPublishTakenow.setOnClickListener {
            getBaseActivity().route(PublishActivity::class.java)
        }

        binding.tvPublishMovieCut.setOnClickListener {

        }

        binding.tvPublishUpload.setOnClickListener {
            val videoPath = Environment.getExternalStorageDirectory().absolutePath+ File.separator+ ConstantValue.RECODE_VIDEO_FILENAME
            val file = File(videoPath)
            if (!file.exists()){
                showMsg("上传的本地文件不存在")
                return@setOnClickListener
            }

            val dialog = ProgressDialog.show(getBaseActivity(),"视频上传","视频上传中...")

            AliOssUtils.uploadObject(ConstantValue.RECODE_VIDEO_FILENAME,videoPath,object :Callback{
                override fun <T> onSuccess(t: T) {
                    showMsg("文件上传成功")
                    dialog.dismiss()
                }

                override fun onFailed(throwable: Throwable) {
                    showMsg("文件上传失败，errinfo:${throwable.message}")
                    dialog.dismiss()
                }

                override fun onProgress(currentSize: Long, totalSize: Long) {

                }

            })

        }
    }

    override fun initView() {
        super.initView()

    }



    override fun generateFragmentRootView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentPublishBinding.inflate(inflater,container,false)
        return binding.root
    }

    override fun lazyLoad() {
    }
}